var banrdPage = {};

$(function () {
  var curIndex = 0
    , heightList = []
    , height = 0;
  var myBScroll = new BScroll('.history_wrapper', {probeType: 2});
  var content = document.querySelectorAll('.history_content li');
  heightList.push(0);
  content = Array.prototype.slice.call(content);
  content.forEach(function (e) {
    height += e.clientHeight;
    heightList.push(height)
  });
  myBScroll.on('scroll', onScroll);

  function onScroll(o) {

    var y = -o.y;

    if (y < 0) {
      curIndex = 0;
      curIndexChange(curIndex);
      return
    }

    for (var i = 0; i < heightList.length - 1; i++) {
      var h1 = heightList[i],
        h2 = heightList[i + 1];
      if (y >= h1 && y < h2) {
        curIndex = i;
        curIndexChange(curIndex);
        return
      }
    }

    curIndex = heightList.length - 2;
    curIndexChange(curIndex);
  }

  function curIndexChange(index) {
    $('.brand_history_nav li').eq(index).addClass('active').siblings().removeClass('active');
    console.log(index)
  }

  window.myBScroll = myBScroll;
  window.content = content

});



banrdPage.init = function () {



  TweenMax.set(history_list, {x: '100%'});
  // historyListSlideToggle()

  $('.history_1930_1979').off().click(function () {
    myBScroll.scrollToElement(content[0], 0);
    $('.brand_history_nav li').eq(0).addClass('active').siblings().removeClass('active');
    // $('.back_home').off().one('click.list', function () {
    //   $('.menu').slideToggle('slow');
    // });
    TweenMax.to('.history_list', .4, {x: '0%'});
    // historyListSlideToggle()
  });
  $('.history_1980_1999').off().click(function () {
    myBScroll.scrollToElement(content[1], 0);
    $('.brand_history_nav li').eq(1).addClass('active').siblings().removeClass('active');
    TweenMax.to('.history_list', .4, {x: '0%'});
    // historyListSlideToggle()
  });
  $('.history_2000_2009').off().click(function () {
    myBScroll.scrollToElement(content[2], 0);
    $('.brand_history_nav li').eq(2).addClass('active').siblings().removeClass('active');
    TweenMax.to('.history_list', .4, {x: '0%'});
    // historyListSlideToggle()
  });
  $('.history_2010_2018').off().click(function () {
    myBScroll.scrollToElement(content[3], 0);
    $('.brand_history_nav li').eq(3).addClass('active').siblings().removeClass('active');
    TweenMax.to('.history_list', .4, {x: '0%'});
    // historyListSlideToggle()
  });
};

banrdPage.hide = function () {

  $('#HOME_PAGE').fadeIn();
  $('#BRAND_HISTORY').fadeOut();
};

